package tictactoe.Service;

import tictactoe.Display.Display;
import tictactoe.Domain.Game;

/**
 * Created with IntelliJ IDEA.
 * User: gmatt
 * Date: 24.11.2012
 * Time: 13:19
 */
public class Application {

    private Game game;

    private Display display;

    public Game getGame() {
        return game;
    }

    public Display getDisplay() {
        return display;
    }

    public Application() {
        initialize();
    }

    public void initialize() {
        game = new Game();
        display = new Display();
        display.setApp(this);
    }

    public void changeState(int index) {
        game.changeState(index);
        display.showResult(index, game.getState(index));
        if ( game.checkForWin() ) {
            display.winResult(game.getPlayer());
            initialize();
        }
        if ( game.fullBoard() ) {
            display.winResult(null);
            initialize();
        }
    }

    public static void main ( String[] args ) {
        new Application();
    }

}
